package com.easy.user.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.easy.common.bean.SysUser;
import com.easy.common.service.IUserService;
import com.easy.common.util.ResultData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("user")
@RestController
@CrossOrigin
public class UserController {
    @Autowired
    IUserService userService;
    @GetMapping("list")
    public ResultData getAllUser(SysUser user){
        List<SysUser> list= userService.getList(user);
        return ResultData.success(list);
    }

    @GetMapping("page")
    public ResultData getByPage(Page page , SysUser user){
        IPage<SysUser> list= userService.getListByPage(page,user);
        return ResultData.success(list);
    }
    @PostMapping("/")
    public ResultData addUser(@RequestBody  SysUser user){
        SysUser newuser=userService.insert(user);
        return ResultData.success(newuser);
    }
    @DeleteMapping("/{id}")
    public ResultData deleteUser(Integer id){
        userService.delete(id);
        return ResultData.success();
    }
    @PutMapping("/")
    public ResultData editUser(@RequestBody  SysUser user){
        SysUser newUser=userService.update(user);
        return ResultData.success(newUser);
    }

}
